{% extends "base1.html" %}

{% block styles %}
    <style>
        /* 设置页面容器样式 */
        .container.mt-4 {
            
            height: calc(100vh - 0px);

            display: flex;
            flex-direction: column;
            padding-bottom: 100px; /* 为footer预留空间 */
        }

        /* 表格容器样式 */
        .table-container-wrapper {
            flex: 1;
            min-height: 0;
            position: relative;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }

        .table-container {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            overflow-y: auto;
            border-radius: 8px;
        }

        /* 自定义滚动条 */
        .table-container::-webkit-scrollbar {
            width: 18px;
        }

        .table-container::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 6px;
        }

        .table-container::-webkit-scrollbar-thumb {
            background: var(--tech-secondary);
            border-radius: 6px;
            border: 3px solid #f1f1f1;
        }

        /* 表格头部固定 */
        .table-container table thead th {
            position: sticky;
            top: 0;
            background: var(--tech-secondary);
            color: white;
            z-index: 1;
            padding: 8px 6px;
        }

        /* 增大checkbox尺寸的样式 */
        input[type="checkbox"] {
            width: 24px;
            height: 24px;
            margin: 8px;
            cursor: pointer;
            position: relative;
            -webkit-appearance: none;
            -moz-appearance: none;
            appearance: none;
            background: #fff;
            border: 2px solid var(--tech-primary);
            border-radius: 4px;
            transition: all 0.3s ease;
        }

        input[type="checkbox"]:checked {
            background: var(--tech-primary);
            border-color: var(--tech-primary);
        }

        input[type="checkbox"]:checked::after {
            content: '✓';
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: white;
            font-size: 16px;
            font-weight: bold;
        }

        /* 增大可点击区域 */
        th:first-child, td:first-child {
            min-width: 50px;
            text-align: center;
        }

        /* 优化表格行高度和悬停效果 */
        .table td, .table th {
            padding: 0.5rem;
            vertical-align: middle;
        }

        #markerConfigTable td, #markerConfigTable th {
            padding: 0.4rem;
        }

        .table tbody tr {
            transition: all 0.2s ease;
        }

        .table tbody tr:hover {
            background-color: rgba(0,0,0,0.02);
        }


        .marker-badge {
            display: inline-block;
            background-color: #1976d2;
            color: white;
            padding: 4px 8px;
            margin: 2px;
            border-radius: 12px;
            font-size: 14px;
            font-weight: 500;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            transition: all 0.2s ease;
        }
        
        .marker-badge:hover {
            background-color: #1565c0;
            transform: translateY(-1px);
        }

        /* 卡片样式优化 */
        .card {
            height: 100%;
            display: flex;
            flex-direction: column;
            border: none;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        .card-body {
            flex: 1;
            display: flex;
            flex-direction: column;
            padding: 1.5rem;
        }

        /* 选中点位容器样式优化 */
        .selected-markers-container {
            margin-bottom: 1rem !important;
            background-color: #f8f9fa !important;
            border-left: 4px solid var(--tech-primary) !important;
        }
    </style>
{% endblock %}

{% block content %}
<div class="container mt-4">
    <h3 class="mb-4">点位配置         
        <button type="button" class="btn btn-primary btn-sm me-2" data-bs-toggle="modal" data-bs-target="#markerConfigModal">
              <i class="fas fa-plus me-1"></i> 新增点位
        </button>
        <button type="button" class="btn btn-success btn-sm me-2" id="syncMarkersButton">
              <i class="fas fa-sync me-1"></i> 同步机器人点位
        </button>
        <button type="button" class="btn btn-danger btn-sm me-2" id="clearMarkersButton">
              <i class="fas fa-trash me-1"></i> 清空点位
        </button>
        <button type="button" class="btn btn-info btn-sm me-2" id="createTaskButton">
              <i class="fas fa-tasks me-1"></i> 创建盘点任务
        </button>
        <div class="input-group" style="width: 240px; display: inline-flex; margin-left: 0.5rem">
            <input type="text" class="form-control" id="searchInput" placeholder="搜索点位名称或简写...">
            <button class="btn btn-primary" type="button" id="searchButton" title="搜索">
                <i class="bi bi-search"></i>
            </button>
        </div>
    </h3>

    <div class="card">
        <div class="card-body">
            <div class="selected-markers-container mb-3 p-2 rounded shadow-sm">
                <span class="fw-bold">当前选中点位: </span>
                <span id="selectedMarkersList" class="text-primary fw-medium">无</span>
            </div>

            <div class="table-container-wrapper">
                <div class="table-container">
                    <table class="table table-striped table-hover mb-0">
                        <thead>
                            <tr>
                                <th><input type="checkbox" id="selectAllCheckbox"></th>
                                <th>ID</th>
                                <th>点位名称1</th>
                                
                                <th>点位简写</th>
                                <th>X坐标</th>
                                <th>Y坐标</th>
                                <th>宽度</th>
                                <th>高度</th>
                                
                                <th>点位名称2</th>
                                <th>X2坐标</th>
                                <th>Y2坐标</th>
                                <th>宽度2</th>
                                <th>高度2</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody id="markerConfigTable">
                            <!-- Data will be loaded here -->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Add/Edit Modal -->
<div class="modal fade" id="markerConfigModal" tabindex="-1" aria-labelledby="markerConfigModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="markerConfigModalLabel">点位配置</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <form id="markerConfigForm">
                    <input type="hidden" id="configId">
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label for="mid" class="form-label">点位名称1</label>
                            <input type="text" class="form-control" id="mid" required>
                        </div>
                        <div class="col-md-6">
                            <label for="mid2" class="form-label">点位名称2</label>
                            <input type="text" class="form-control" id="mid2">
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label for="midShort" class="form-label">点位简写</label>
                            <input type="text" class="form-control" id="midShort" required>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label for="x" class="form-label">X坐标</label>
                            <input type="number" class="form-control" id="x" value="0" required>
                        </div>
                        <div class="col-md-6">
                            <label for="y" class="form-label">Y坐标</label>
                            <input type="number" class="form-control" id="y" value="0" required>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label for="w" class="form-label">宽度</label>
                            <input type="number" class="form-control" id="w" value="0" required>
                        </div>
                        <div class="col-md-6">
                            <label for="h" class="form-label">高度</label>
                            <input type="number" class="form-control" id="h" value="0" required>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label for="x2" class="form-label">X2坐标</label>
                            <input type="number" class="form-control" id="x2" value="0" required>
                        </div>
                        <div class="col-md-6">
                            <label for="y2" class="form-label">Y2坐标</label>
                            <input type="number" class="form-control" id="y2" value="0" required>
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <label for="w2" class="form-label">宽度2</label>
                            <input type="number" class="form-control" id="w2" value="0" required>
                        </div>
                        <div class="col-md-6">
                            <label for="h2" class="form-label">高度2</label>
                            <input type="number" class="form-control" id="h2" value="0" required>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="saveButton">保存</button>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script src="{{ url_for('static', filename='js/marker-config.js') }}"></script>
{% endblock %}
